package com.wolfcode.visit.service.impl;

import java.util.List;

import com.wolfcode.common.utils.DateUtils;
import com.wolfcode.common.utils.SecurityUtils;
import com.wolfcode.visit.domain.vo.CustomerVisitVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wolfcode.visit.mapper.CustomerVisitMapper;
import com.wolfcode.visit.domain.CustomerVisit;
import com.wolfcode.visit.service.ICustomerVisitService;
import org.springframework.util.Assert;

/**
 * 拜访信息Service业务层处理
 * 
 * @author wolfcode
 * @date 2022-12-09
 */
@Service
public class CustomerVisitServiceImpl implements ICustomerVisitService 
{
    @Autowired
    private CustomerVisitMapper customerVisitMapper;

    /**
     * 查询拜访信息
     * 
     * @param id 拜访信息主键
     * @return 拜访信息
     */
    @Override
    public CustomerVisit selectCustomerVisitById(Long id)
    {
        return customerVisitMapper.selectCustomerVisitById(id);
    }

    /**
     * 查询拜访信息列表
     * 
     * @param customerVisit 拜访信息
     * @return 拜访信息
     */
    @Override
    public List<CustomerVisit> selectCustomerVisitList(CustomerVisit customerVisit)
    {
        return customerVisitMapper.selectCustomerVisitList(customerVisit);
    }

    /**
     * 新增拜访信息
     * 
     * @param customerVisitVo 拜访信息
     * @return 结果
     */
    @Override
    public int insertCustomerVisit(CustomerVisitVo customerVisitVo)
    {
        Assert.notNull(customerVisitVo,"非法参数");
        Assert.notNull(customerVisitVo.getCustomerId(),"访问的企业不能为空");
        Assert.notNull(customerVisitVo.getLinkmanId(),"访问的企业联系人不能为空");
        Assert.notNull(customerVisitVo.getVisitType(),"请选择访问方式");
        Assert.notNull(customerVisitVo.getVisitReason(),"拜访原因");
        Assert.notNull(customerVisitVo.getVisitDate(),"访问的企业联系人不能为空");
        Assert.state(customerVisitVo.getVisitDate().before(DateUtils.getNowDate()),"拜访时间是在当前时间之前");
        CustomerVisit customerVisit = new CustomerVisit();
        BeanUtils.copyProperties(customerVisitVo,customerVisit);
        customerVisit.setInputUser(SecurityUtils.getUserId());
        customerVisit.setInputTime(DateUtils.getNowDate());
        return customerVisitMapper.insertCustomerVisit(customerVisit);
    }

    /**
     * 修改拜访信息
     * 
     * @param customerVisit 拜访信息
     * @return 结果
     */
    @Override
    public int updateCustomerVisit(CustomerVisit customerVisit)
    {
        return customerVisitMapper.updateCustomerVisit(customerVisit);
    }

    /**
     * 批量删除拜访信息
     * 
     * @param ids 需要删除的拜访信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerVisitByIds(Long[] ids)
    {
        return customerVisitMapper.deleteCustomerVisitByIds(ids);
    }

    /**
     * 删除拜访信息信息
     * 
     * @param id 拜访信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerVisitById(Long id)
    {
        return customerVisitMapper.deleteCustomerVisitById(id);
    }
}
